import { judgeDevice } from "@/utils/tools";
import { createRouter, createWebHistory } from "vue-router";

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: "/",
      name: "home",
      component: () => import("@/views/home/index.vue"),
      children: [
        {
          path: "article/:id",
          name: "article",
          component: () => import("@/views/article/index.vue"),
          meta: {
            name: "文章详情",
          },
        },
      ],
      meta: {
        name: "首页",
      },
    },
    {
      path: "/music",
      name: "music",
      component: () => import("@/views/music/index.vue"),
      meta: {
        name: "音乐",
      },
      children: [
        {
          path: "search",
          name: "musicSearch",
          component: () => import("@/views/musicSearch/index.vue"),
          meta: {
            name: "搜索音乐",
          },
        },
        {
          path: "singerDetail/:id",
          name: "singerDetail",
          component: () => import("@/views/singerDetail/index.vue"),
          meta: {
            name: "歌手详情",
          },
        },
        {
          path: "albumDetail/:id",
          name: "albumDetail",
          component: () => import("@/views/albumDetail/index.vue"),
          meta: {
            name: "专辑详情",
          },
        },
        {
          path: "songListDetail/:id",
          name: "songListDetail",
          component: () => import("@/views/songListDetail/index.vue"),
          meta: {
            name: "歌单详情",
          },
        },
      ],
    },
    {
      path: "/game",
      name: "game",
      component: () => import("@/views/game/index.vue"),
      children: [
        {
          path: "detail/:id",
          name: "detail",
          component: () => import("@/views/gameDetail/index.vue"),
          meta: {
            name: "游戏详情",
          },
        },
      ],
      meta: {
        name: "游戏",
      },
    },
    {
      path: "/pixiv",
      name: "pixiv",
      component: () => import("@/views/pixiv/index.vue"),
      meta: {
        name: "插画",
      },
    },
    {
      path: "/me",
      name: "me",
      component: () => import("@/views/me/index.vue"),
      meta: {
        name: "关于",
      },
    },
  ],
});

router.beforeEach(() => {
  if (!judgeDevice()) {
    location.href = "https://www.fasyncsy.com.cn";
  }
});

router.afterEach((to) => {
  document.title = `F's Blog | ${(to.meta.name as string) || ""}`;
});

export default router;
